//
//  WYReceiveListCell.m
//  Boss
//
//  Created by admin on 2018/6/2.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYReceiveListCell.h"
#import "WYRedPackerPersonCell.h"
#import "WYReceiveUserList.h"
@interface WYReceiveListCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (strong, nonatomic) IBOutlet UICollectionView *colllectionView;
@property (strong, nonatomic) IBOutlet UIButton *statusBtn;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *collectionViewHeight;


@end
@implementation WYReceiveListCell
-(void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    
    [self.colllectionView reloadData];
    
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    self.collectionViewHeight.constant = (kScreenWidth-100-7)/7.0 +20;
    // Initialization code
    [self setUpUI];
}
-(void)setUpUI
{
    [self.statusBtn setCornerRadius:5.0f];
    [self.statusBtn setBorderWithWidth:kLineHeight andColor:kColorMainColor];
    [self.statusBtn setTitleColor:kColorMainColor forState:(UIControlStateNormal)];
    self.colllectionView.delegate = self;
    self.colllectionView.dataSource = self;
    
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    layout.itemSize=CGSizeMake((kScreenWidth-100-7)/7.0, (kScreenWidth-100-7)/7.0);
    //横向最小距离
    layout.minimumInteritemSpacing=5.0f;
    layout.minimumLineSpacing=5.0f;
    //cell距离上  左  下 右 的距离
    layout.sectionInset=UIEdgeInsetsMake(10, 10, 10, 10);
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    [self.colllectionView setCollectionViewLayout:layout];
  //  [layout setHeaderReferenceSize:CGSizeMake(kScreenWidth, 44)];
    [self.colllectionView registerNib:[UINib nibWithNibName:@"WYRedPackerPersonCell" bundle:nil] forCellWithReuseIdentifier:@"WYRedPackerPersonCell"];
    
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArray.count > 7 ? 7:self.dataArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    WYRedPackerPersonCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WYRedPackerPersonCell" forIndexPath:indexPath];
    if (!cell) {
        cell =[[NSBundle mainBundle] loadNibNamed:@"WYRedPackerPersonCell" owner:nil options:nil].firstObject;
    }
    [cell.personImageView setBackgroundColor:kColorMainColor];
    
    WYReceiveUserList *list = self.dataArray[indexPath.item];
    [cell.personImageView sd_setImageWithURL:[NSURL URLWithString:list.userPhoto] placeholderImage:[UIImage imageNamed:@"ic_defult_avatar"]];
    [cell.personImageView setCornerRadius:((kScreenWidth-100-7)/7.0)/2.0];
    return cell;
}
//- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
//{
//    if (section==0) {
//        return UIEdgeInsetsMake(10, 16, 0, 0);
//    }
//
//
//
//    return  UIEdgeInsetsMake(10, 10, 0, 0);
//}







@end
